package com.kaili.basic.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.kaili.basic.mapper.BaseDictMapper;
import com.kaili.basic.mapper.BaseEmployeeMapper;
import com.kaili.basic.mapper.BasePdaMapper;
import com.kaili.basic.mapper.BasicSiteMapper;
import com.kaili.basic.pojo.dto.BasePdaAddDto;
import com.kaili.basic.pojo.dto.BasePdaQueryDto;
import com.kaili.basic.pojo.entity.BasePda;
import com.kaili.basic.service.BasePdaService;
import com.kaili.common.util.LoginDetailUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created by renzhikun on 18-6-21.
 */
@Service
public class BasePdaServiceImpl implements BasePdaService {

    @Autowired
    private BasePdaMapper basePdaMapper;
    @Autowired
    private BaseDictMapper dictMapper;
    @Autowired
    private BaseEmployeeMapper employeeMapper;
    @Autowired
    private BasicSiteMapper siteMapper;

    @Override
    public void addBasePda(BasePdaAddDto dto) {
        Integer uid = LoginDetailUtils.getCurrentEmployeeId();
        if (uid != null) {
            BasePda basePda = new BasePda();
            BeanUtils.copyProperties(dto,basePda);

            Date now = new Date();
            basePda.setCreateBy(uid.longValue());
            basePda.setCreateTime(now);
            basePda.setModifyBy(uid.longValue());
            basePda.setModifyTime(now);
            basePdaMapper.addBasePda(basePda);
        }
    }

    @Override
    public void deleteBasePda(Long pdaId) {
        Map<String, Object> map = new HashMap();
        Integer uid = LoginDetailUtils.getCurrentEmployeeId();
        if (uid != null) {
            map.put("modifyBy", uid.longValue());
            map.put("pdaId",pdaId);
            basePdaMapper.deleteBasePda(map);
        }
    }

    @Override
    public void updateBasePda(BasePdaAddDto dto) {
        Integer uid = LoginDetailUtils.getCurrentEmployeeId();
        if (uid != null) {
            BasePda basePda = new BasePda();
            BeanUtils.copyProperties(dto,basePda);

            basePda.setModifyBy(uid.longValue());
            basePdaMapper.updateBasePda(basePda);
        }
    }

    @Override
    public Page<BasePda>  queryBasePda(Page<BasePda> page, BasePdaQueryDto dto) {
        List<BasePda> list = basePdaMapper.queryBasePda(page, dto);
        return page.setRecords(list);
    }

    @Override
    public List<String> selectBySn(String pdaSn) {
        return basePdaMapper.selectBySn(pdaSn);
    }

    @Override
    public List<String> veriBySn(String pdaSn) {
        return basePdaMapper.veriBySn(pdaSn);
    }

    @Override
    public BasePda getBySn(String pdaSn) {
        return basePdaMapper.getBySn(pdaSn);
    }

}
